<?php
/**
 * @copyright  For copyright and license information, read the COPYING.txt file.
 * @link       /COPYING.txt
 * @license    Academic Free License (AFL 3.0)
 * @package     default_default
 */

/**
 * @see Mage_Adminhtml_Block_System_Store_Tree
 * @var Mage_Adminhtml_Block_System_Store_Tree $this
 */
?>

<div class="grid">
    <table class="data" cellspacing="0">
        <thead>
            <tr class="headings">
                <th class="no-link"><span class="nobr"><a href="<?php echo $this->getUrl('*/*/newWebsite') ?>"><?php echo Mage::helper('core')->__('Website Name') ?></a></span></th>
                <th class="no-link"><span class="nobr"><a href="<?php echo $this->getUrl('*/*/newGroup') ?>"><?php echo Mage::helper('core')->__('Store Name') ?></a></span></th>
                <th class="no-link"><span class="nobr"><a href="<?php echo $this->getUrl('*/*/newStore') ?>"><?php echo Mage::helper('core')->__('Store View Name') ?></a></span></th>
            </tr>
        </thead>
        <tbody>
        <?php $printedWebsite = false; ?>
        <?php $printedStoreGroup = false; ?>
        <?php foreach ($this->getTableData() as $webSiteData): ?>
            <?php if (count($webSiteData['storeGroups']) == 0): ?>
                <tr>
                    <?php if (!$printedWebsite): ?>
                        <td class="a-left" rowspan="<?php echo $webSiteData['count'] ?>"><?php echo $this->renderWebsite($webSiteData['object']) ?></td>
                    <?php endif ?>

                    <td colspan="2" class="a-left last"><span class="not-available"></span></td>
                </tr>
                <?php $printedWebsite = false; ?>
                <?php continue ?>
            <?php endif ?>

            <?php foreach ($webSiteData['storeGroups'] as $storeGroupData): ?>
                <?php if (count($storeGroupData['stores']) == 0): ?>
                    <tr>
                        <?php if (!$printedWebsite): ?>
                            <td class="a-left" rowspan="<?php echo $webSiteData['count'] ?>"><?php echo $this->renderWebsite($webSiteData['object']) ?></td>
                            <?php $printedWebsite = true; ?>
                        <?php endif ?>

                        <?php if (!$printedStoreGroup): ?>
                        <td class="a-left" rowspan="<?php echo $storeGroupData['count'] ?>"><?php echo $this->renderStoreGroup($storeGroupData['object']) ?></td>
                        <?php endif ?>

                        <td class="a-left last"><span class="not-available"></span></td>
                    </tr>
                    <?php $printedStoreGroup = false; ?>
                    <?php continue ?>
                <?php endif ?>

                <?php foreach ($storeGroupData['stores'] as $storeData): ?>
                    <tr>
                        <?php if (!$printedWebsite): ?>
                            <td class="a-left" rowspan="<?php echo $webSiteData['count'] ?>"><?php echo $this->renderWebsite($webSiteData['object']) ?></td>
                            <?php $printedWebsite = true; ?>
                        <?php endif ?>

                        <?php if (!$printedStoreGroup): ?>
                        <td class="a-left" rowspan="<?php echo $storeGroupData['count'] ?>"><?php echo $this->renderStoreGroup($storeGroupData['object']) ?></td>
                            <?php $printedStoreGroup = true; ?>
                        <?php endif ?>

                        <td class="a-left last"><?php echo $this->renderStore($storeData['object']); ?></td>
                    </tr>
                <?php endforeach ?>
                <?php $printedStoreGroup = false; ?>
            <?php endforeach ?>
            <?php $printedWebsite = false; ?>
        <?php endforeach ?>
        </tbody>
    </table>
</div>
